package unipi.helpers;

public class Validator 
{
	public static boolean isNumber(String s)
	{
		try
		{
			Integer.parseInt(s);
		}
		catch(NumberFormatException nfe)
		{
			return false;			
		}
		
		return true;		
	}
	
	public static boolean isEmail(String s)
	{
		String regex = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}$";
		
		if(!isValid(s)) return false;
		
		return s.matches(regex);
	}
	
	public static boolean isValid(String s)
	{
		String regex = "^[^\\'\\\"]*$";
		
		return s.matches(regex);
	}

	public static boolean isDate(String s)
	{
		String regex = "^(19|20)\\d\\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$";
		
		return s.matches(regex);
	}
	
	public static String escape(String s)
	{
		return s.replaceAll("'", "&#39;").replaceAll("\"", "&#34;");	
	}
	
}
